<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/5
 * Time: 14:42
 */

namespace app\common\model;
use think\Db;
use think\Model;

class UserAuth extends Model
{
    protected $name = "user_auth";

    public function getUserList ($where, $field, $request,$keyword) {

        if ($keyword) {
            $list =  $this->alias('ua')
                ->join('car_auth ca', 'ua.user_id = ca.user_id', 'left')
                ->field($field)
                ->where($where)
                ->whereOr('ua.nickname|ua.user_id|ua.id|ua.phone','like',"%$keyword%")
                ->order('ua.create_time desc')
                ->paginate(20, false, ['query' => $request->get()]);
        } else {
            $list =  $this->alias('ua')
                ->join('car_auth ca', 'ua.user_id = ca.user_id', 'left')
                ->field($field)
                ->where($where)
                ->order('ua.create_time desc')
                ->paginate(20, false, ['query' => $request->get()]);
        }

        return $list;

    }

    public function getUserInfo($where, $field) {

        $data = $this->alias('ua')
            ->join('user_license ul', 'ua.user_id = ul.user_id', 'left')
            ->field($field)
            ->where($where)
            ->find();

        return $data;
    }

    public function getUserCarInfoList ($where, $field, $request) {

        $list = Db::name('car_auth')
            ->where($where)
            ->field($field)
            ->order('create_time desc')
            ->paginate(20, false, ['query' => $request->get()]);


        return $list;
    }

}